package com.shf.lease.web.admin.controller.apartment;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shf.lease.entity.ApartmentInfo;
import com.shf.lease.enums.ReleaseStatus;
import com.shf.lease.result.Result;
import com.shf.lease.web.admin.controller.apartment.query.QueryApartmentParams;
import com.shf.lease.web.admin.controller.apartment.request.ApartmentCmd;
import com.shf.lease.web.admin.controller.apartment.response.ApartmentDetailVo;
import com.shf.lease.web.admin.controller.apartment.response.PageListApartmentVo;
import com.shf.lease.web.admin.controller.apartment.response.PageListVo;
import com.shf.lease.web.admin.service.ApartmentInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author 叶枫
 * @date 2024/7/5.
 */

@Tag(name = "公寓管理")
@RestController
@RequestMapping("/admin/apartment")
public class ApartmentController {

    @Resource
    private ApartmentInfoService apartmentInfoService;


    @Operation(summary = "分页查询公寓信息")
    @GetMapping("/pageItem")
   public Result<PageListVo<PageListApartmentVo>>
    queryPageListApartment(QueryApartmentParams queryParams){

        return apartmentInfoService.queryPageListApartment(queryParams);
   }

   @Operation(summary = "新增或修改")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdateApartment(@RequestBody ApartmentCmd request){
        return apartmentInfoService.saveOrUpdateApartment(request);
    }

    @Operation(summary="根据id查询公寓详情")
    @GetMapping("/getDetailById")
    public Result<ApartmentDetailVo> getDetailById(@RequestParam("id") Long id){
        return apartmentInfoService.getDetailById(id);
    }

    @Operation(summary = "删除公寓")
    @DeleteMapping("/delete")
    public Result deleteApartment(@RequestParam("id") Long id){
        return apartmentInfoService.deleteApartment(id);
    }

    @Operation(summary = "根据id修改公寓发布状态")
    @PostMapping("updateReleaseStatusById")
    public Result updateReleaseStatusById(@RequestParam Long id, @RequestParam ReleaseStatus status) {

        LambdaUpdateWrapper<ApartmentInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(ApartmentInfo::getId, id);
        updateWrapper.set(ApartmentInfo::getIsRelease, status);
        apartmentInfoService.update(updateWrapper);
        return Result.ok();
    }
}
